/*
 * @Author       : wfl
 * @LastEditors  : wfl
 * @description  :
 * @updateInfo   :
 * @Date         : 2023-11-07 12:14:27
 * @LastEditTime : 2024-01-15 09:38:25
 */
import { Body, Headers, Inject, Post } from '@midwayjs/decorator';
import { CoolController, BaseController, RESCODE } from '@cool-midway/core';
import axios from 'axios';

/**
 * 代理
 */
@CoolController()
export class ProxyController extends BaseController {
  @Post('/')
  async proxy(@Body() body) {
    const { headers } = this.baseCtx;
    try {
      const { method, url } = this.baseCtx;
      const response = await axios({
        method: body.ik_datav_proxy_method,
        url: body.ik_datav_proxy_api,
        headers,
        data: body,
      });
      return response.data;
    } catch (error) {
      return this.ok({
        code: RESCODE.COMMFAIL,
        message: '请求错误',
      });
    }
  }
}
